package Jvm.JvmException;

import java.util.ArrayList;

public class JvmException {

    public static void main(String[] args) {

//        测试前添加JVM参数（限制JVM内存大小）-Xms5m -Xmx5m
//        1.测试堆内存异常
        heapOOM();

//        2.测试栈溢出异常
//        System.out.println(getRabbitNum(20));
    }

    /**
     * 1.测试堆内存异常
     */
    public static void heapOOM(){
        ArrayList<JvmException> jvmExceptionArrayList = new ArrayList<>();

        while (true){
            jvmExceptionArrayList.add(new JvmException());
        }

    }

    /**
     * 2.测试栈溢出异常
     */
    public static int getRabbitNum(int mouth){
        return getRabbitNum(mouth - 1) + getRabbitNum(mouth - 2);
    }

}
